/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.generator;

import java.util.Enumeration;
import java.util.Properties;
import jsf.generator.pages.JSFViewWriter;
import jsf.generator.pages.JSFListWriter;
import jsf.generator.pages.JSFEditWriter;
import jsf.generator.pages.JSFBaseWriter;
import net.db.generator.field.models.BaseFieldModel;

/**
 *
 * @author abosancic
 */
public class CommonJSFPagesGenerator {

    private BaseFieldModel [] fields;
    private String className;
    private String pckg;
    private Properties properties;
    
    public CommonJSFPagesGenerator(String className, BaseFieldModel [] fields) {
        this(className, fields, "pages.");
    }
    
    public CommonJSFPagesGenerator(String className, BaseFieldModel [] fields, String pckg) {
        this.className = className;
        this.fields = fields;
        this.pckg = pckg;
        this.properties = new Properties();
    }
    
    public void generateJSFPages()
    {
        JSFBaseWriter j = new JSFBaseWriter();
        j.setClassName(className);
        j.setFields(fields);
        j.setPackageName(pckg + className);
        j.generateXHTML();
        properties.putAll(j.getProperties());
        
        j = new JSFEditWriter();
        j.setClassName(className);
        j.setFields(fields);
        j.setPackageName(pckg + className);
        j.generateXHTML();
        properties.putAll(j.getProperties());
        
        j = new JSFViewWriter();
        j.setClassName(className);
        j.setFields(fields);
        j.setPackageName(pckg + className);
        j.generateXHTML();
        properties.putAll(j.getProperties());
        
        j = new JSFListWriter();
        j.setClassName(className);
        j.setFields(fields);
        j.setPackageName(pckg + className);
        j.generateXHTML();
        properties.putAll(j.getProperties());
    }

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }
    
    /**
     * Copy a set of properties from one Property to another.
     * <p>
     *
     * @param src_prop Source set of properties to copy from.
     * @param dest_prop Dest Properties to copy into.
     *
     *
     */
    public static void copyProperties(Properties src_prop, Properties dest_prop) {
        for (Enumeration propertyNames = src_prop.propertyNames();
                propertyNames.hasMoreElements();) {
            Object key = propertyNames.nextElement();
            dest_prop.put(key, src_prop.get(key));
        }
    }

}


//JSFBaseWriter j = new JSFBaseWriter();
//        j.setClassName(className);
//        j.setFields(fields);
//        j.setPackageName(pckg + className);
//        j.generateXHTML();
//        copyProperties(j.getProperties(), properties);
//        
//        j = new JSFEditWriter();
//        j.setClassName(className);
//        j.setFields(fields);
//        j.setPackageName(pckg + className);
//        j.generateXHTML();
//        copyProperties(j.getProperties(), properties);
//        
//        j = new JSFViewWriter();
//        j.setClassName(className);
//        j.setFields(fields);
//        j.setPackageName(pckg + className);
//        j.generateXHTML();
//        copyProperties(j.getProperties(), properties);
//        
//        j = new JSFListWriter();
//        j.setClassName(className);
//        j.setFields(fields);
//        j.setPackageName(pckg + className);
//        j.generateXHTML();
//        copyProperties(j.getProperties(), properties);